﻿using System;
using ApiGateway;
using HttpApiGateway.Model;
using RpcClient;
using RpcHelper.Validate;
using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Gateway.Model;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Gateway.Controller
{
    /// <summary>
    /// 网管Ip黑名单
    /// </summary>
    internal class IpBlackController : HttpApiGateway.ApiController
    {
        private readonly IIpBlackService _Service;

        public IpBlackController(IIpBlackService service)
        {
            this._Service = service;
        }

        /// <summary>
        /// 添加黑名单
        /// </summary>
        /// <param name="add"></param>
        /// <returns></returns>
        public int Add(AddIpBlackParam add)
        {
            return this._Service.Add(add);
        }
        /// <summary>
        /// 删除黑名单
        /// </summary>
        /// <param name="id"></param>
        public void Drop([NumValidate("rpc.store.ipBlack.id.error", 1, int.MaxValue)] int id)
        {
            this._Service.Drop(id);
        }
        /// <summary>
        /// 获取黑名单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public IpBlackDatum Get([NumValidate("rpc.store.ipBlack.id.error", 1, int.MaxValue)] int id)
        {
            return this._Service.Get(id);
        }
        /// <summary>
        /// 查询黑名单
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public PagingResult<IpBlack> Query(PagingParam<IpBlackQuery> param)
        {
            IpBlack[] list= this._Service.Query(param.Param, param.ToBasicPaging(), out long count);
            return new PagingResult<IpBlack>(list, count);
        }
        /// <summary>
        /// 修改黑名单
        /// </summary>
        /// <param name="set"></param>
        /// <returns></returns>
        public int Set(IntParam<SetIpBlackParam> set)
        {
            return this._Service.Set(set.Id, set.Param);
        }
        /// <summary>
        /// 设置IP黑名单备注
        /// </summary>
        /// <param name="param"></param>
        public void SetRemark(IntParam<string> param)
        {
            this._Service.SetRemark(param.Id, param.Param);
        }
    }
}
